package com.dormitory.javadormitory.common;

import com.fasterxml.jackson.annotation.JsonInclude;

public class Result {
    private Integer code;
    private String message;
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Object data;

    public Result() {

    }

    public Result(Integer code) {
        this.code = code;
    }

    public Result(String message) {
        this.message = message;
    }

    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Result(Integer code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }



    public static Result success() {
        return new Result(200,"操作成功");
    }

    public static Result success(Object data) {
        return new Result(200,"操作成功",data);
    }

    public static Result error(Integer code){
        return new Result(code,ResultEnum.getMessageByCode(code));
    }

    //未查询到提示
    public static Result error(String msg){
        return new Result(500,msg);
    }

    public static Result error(Integer code, String msg){
        return new Result(code,msg);
    }

    public static Result error(){
        return new Result(500,"系统错误，请联系管理员");
    }

}
